clc
clear all
close all




a=load('step_PWM_posicao_angular_entrada_matlab.txt');
% cortando os vetores pela metade:
a=a(1:440,:);

a(:,1)=a(:,1)/2000+1.5;
t=0:1/50:1/50*(numel(a(:,1))-1);
t=t';

h1 = figure(1);
hold on
[AX,H1,H2]=plotyy(t,a(:,1),t,a(:,2));

set(get(AX(1),'Ylabel'),'String','PWM Pulse Width (10^-^3s)');
set(get(AX(2),'Ylabel'),'String','Servo Position (deg)');
xlabel('Time (s)');

set(AX(1),'YTick',[1 1.5 2 2.5]);
set(AX(2),'YTick',[-45 0 45 90]);

set(H1,'LineStyle','-');
set(H2,'LineStyle','--');
% set(H2,'LineStyle','--','LineWidth',2);

set(AX(1),'YLim',[0.75 2.75]);
set(AX(2),'YLim',([0.75 2.75]-1.5)*45/.5);
% set(AX(2),'YLim',([-1500 1500]*90/2000));  % rela��o: 2ms = 90� 

%%% ADICIONANDO GRIDXY
ax=axis;
grid_space=[1 0.025 0.5 .5];
x_1=ax(1):grid_space(1):ax(2);
% x_2=ax(1):grid_space(2):ax(2);
y_1=1:grid_space(3):2.5;
% y_2=ax(3):grid_space(4):ax(4);
gridxy(x_1,y_1,'LineStyle',':','Color',[.5 .5 .5]);
% gridxy(x_2,y_2,'LineStyle',':','Color',[.5 .5 .5]);

legend([H1 H2],'PWM Pulse Width','Servo Position');

ratio=[3 1 1];
pbaspect(AX(1),ratio);
pbaspect(AX(2),ratio);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

a=load ('step_PWM_posicao_angular_saida_matlab.txt');
% cortando os vetores pela metade:
a=a(1:440,:);

t=0:1/50:1/50*(numel(a(:,1))-1);
t=t';

h2=figure(2);
hold on
plot(t,a(:,1),'.b');
plot(t,a(:,2),'k');
% plot(t,a(:,2),'k','LineWidth',2);
xlabel('Time (s)');
ylabel('Servo Position (deg)');
set(gca,'YLim',[-67.5 112.5]);
set(gca,'YTick',[-45 0 45 90]);
legend('Test Data','Model Prediction');

ratio=[3 1 1];
pbaspect(ratio);
set(gca,'box','on')

%%% ADICIONANDO GRIDXY
ax=axis;
grid_space=[1 0.025 1 .5];
x_1=ax(1):grid_space(1):ax(2);
y_1=-45:45:90;
gridxy(x_1,y_1,'LineStyle',':','Color',[.5 .5 .5]);

print(h1,'-depsc2','-painters','ensaio_servo.eps');
print(h2,'-depsc2','-painters','modelo_servo.eps');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

a=load('sweep_PWM_RPM_entrada_matlab.txt');
% cortando os vetores pela metade:
a=a(1:2200,:);

a(:,1)=(a(:,1)+(3150+2500)/2)/2;    % recompondo a largura PWM comandada
a(:,2)=a(:,2)+9000;   % somando 9000 RPM do estado estacion�rio
t=0:1/50:1/50*(numel(a(:,1))-1);
t=t';

h3 = figure(3);
hold on
[AX,H1,H2]=plotyy(t,a(:,1),t,a(:,2));

set(get(AX(1),'Ylabel'),'String','PWM Pulse Width (10^-^3s)');
set(get(AX(2),'Ylabel'),'String','Propeller Rotation (RPM)');
xlabel('Time (s)');

aux=[1250-325*1/4 1575+325*3/4];
set(AX(1),'YLim',aux);
set(AX(2),'YLim',(aux-1250) * 4000/325 + 7000 );%convertendo: PWM p/ RPM

set(H1,'LineStyle','-')
set(H2,'LineStyle','--');

set(AX(1),'YTick',[1250 1250+325/2 1575 1575+325/2]);
set(AX(2),'YTick',[7000 9000 11000 13000]);
set(AX(2),'YTickLabel',num2str(get(AX(2),'YTick').'));

legend([H1 H2],'PWM Pulse Width','Propeller Rotation');

ratio=[3 1 1];
pbaspect(AX(1),ratio);
pbaspect(AX(2),ratio);

%%% ADICIONANDO GRIDXY
ax=axis;
grid_space=[5 0.025 1 .5];
x_1=ax(1):grid_space(1):ax(2);
y_1=1250:325/2:1737.5;
gridxy(x_1,y_1,'LineStyle',':','Color',[.5 .5 .5]);



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

a=load('sweep_PWM_RPM_saida_matlab.txt');
% cortando os vetores pela metade:
a=a(1:2200,:);

a(:,1)=a(:,1)+9000;   % somando 9000 RPM do estado estacion�rio
a(:,2)=a(:,2)+9000;   % somando 9000 RPM do estado estacion�rio
t=0:1/50:1/50*(numel(a(:,1))-1);
t=t';

h4=figure(4);
hold on
plot(t,a(:,1),'.b');
plot(t,a(:,2),'k');
% plot(t,a(:,2),'k','LineWidth',2);
xlabel('Time (s)');
ylabel('Propeller Rotation (RPM)');
legend('Test Data','Model Prediction');

aux=[7000-4000*1/4 11000+4000*3/4];
set(gca,'YLim',aux);
set(gca,'YTick',[7000 9000 11000 13000]);
set(gca,'YTickLabel',num2str(get(gca,'YTick').'));
ratio=[3 1 1];
pbaspect(ratio);
set(gca,'box','on')

%%% ADICIONANDO GRIDXY
ax=axis;
grid_space=[5 0.025 1 .5];
x_1=ax(1):grid_space(1):ax(2);
y_1=7000:2000:13000;
gridxy(x_1,y_1,'LineStyle',':','Color',[.5 .5 .5]);

print(h3,'-depsc2','-painters','ensaio_sweep.eps');
print(h4,'-depsc2','-painters','modelo_sweep.eps');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

a=load('steps_PWM_RPM_entrada_matlab.txt');
a(:,1)=(a(:,1)+(3150+2500)/2)/2;    % recompondo a largura PWM comandada
a(:,2)=a(:,2)+9000;   % somando 9000 RPM do estado estacion�rio
t=0:1/50:1/50*(numel(a(:,1))-1);
t=t';

h5 = figure(5);
hold on
[AX,H1,H2]=plotyy(t,a(:,1),t,a(:,2));

set(get(AX(1),'Ylabel'),'String','PWM Pulse Width (10^-^3s)');
set(get(AX(2),'Ylabel'),'String','Propeller Rotation (RPM)');
xlabel('Time (s)');

aux=[1250-325*1/4 1575+325*3/4];
set(AX(1),'YLim',aux);
set(AX(2),'YLim',(aux-1250) * 4000/325 + 7000 );%convertendo: PWM p/ RPM

set(H1,'LineStyle','-')
set(H2,'LineStyle','--');

set(AX(1),'YTick',[1250 1250+325/2 1575 1575+325/2]);
set(AX(2),'YTick',[7000 9000 11000 13000]);
set(AX(2),'YTickLabel',num2str(get(AX(2),'YTick').'));

legend([H1 H2],'PWM Pulse Width','Propeller Rotation');

ratio=[3 1 1];
pbaspect(AX(1),ratio);
pbaspect(AX(2),ratio);

%%% ADICIONANDO GRIDXY
ax=axis;
grid_space=[5 0.025 1 .5];
x_1=ax(1):grid_space(1):ax(2);
y_1=1250:325/2:1737.5;
gridxy(x_1,y_1,'LineStyle',':','Color',[.5 .5 .5]);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

a=load('steps_PWM_RPM_saida_matlab.txt');
a(:,1)=a(:,1)+9000;   % somando 9000 RPM do estado estacion�rio
a(:,2)=a(:,2)+9000;   % somando 9000 RPM do estado estacion�rio
t=0:1/50:1/50*(numel(a(:,1))-1);
t=t';

h6=figure(6);
hold on
plot(t,a(:,1),'.b');
plot(t,a(:,2),'k');
% plot(t,a(:,2),'k','LineWidth',2);
xlabel('Time (s)');
ylabel('Propeller Rotation (RPM)');
legend('Test Data','Model Prediction');

aux=[7000-4000*1/4 11000+4000*3/4];
set(gca,'YLim',aux);
set(gca,'YTick',[7000 9000 11000 13000]);
set(gca,'YTickLabel',num2str(get(gca,'YTick').'));
set(gca,'box','on')
ratio=[3 1 1];
pbaspect(ratio);

% plot2svg('filename.svg',h3);

%%% ADICIONANDO GRIDXY
ax=axis;
grid_space=[5 0.025 1 .5];
x_1=ax(1):grid_space(1):ax(2);
y_1=7000:2000:13000;
gridxy(x_1,y_1,'LineStyle',':','Color',[.5 .5 .5]);

print(h5,'-depsc2','-painters','ensaio_step.eps');
print(h6,'-depsc2','-painters','modelo_step.eps');

